<script lang="ts" setup>
import { get, post, message, loadFile } from '@/utils'
import useTable, { MyProColumns } from '@/hooks/useTable'
const props = defineProps<{
  show: boolean
  id: number | string
}>()
const emit = defineEmits(['update:show', 'reset', 'confirm'])
const { formatColumns } = useTable()
const searchQuery = reactive({
  sellerId: props.id,
})
const actionRef = ref()
const formRef = ref()
const pagination = {
  showPageSize: true,
  pageSize: 20,
}
const request = (params: any, sort: any, filters: any): Promise<any> => {
  return new Promise((resolve, reject) => {
    const query = { ...params, size: params.pageSize }
    Reflect.deleteProperty(query, 'pageSize')
    get(
      {
        url: '/server-shop/admin/seller/wallet/page',
        data: query,
      },
      ({ data }) => {
        resolve({
          data: data.records,
          total: data.total,
          success: true,
        })
      }
    )
  })
}
const columns = formatColumns([
  {
    title: '变动金额',
    dataIndex: 'amount',
    width: 150,
  },
  {
    title: '剩余金额',
    dataIndex: 'amountLast',
    width: 150,
  },
  {
    title: '说明',
    dataIndex: 'explains',
    width: 150,
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 150,
  },
  {
    title: '来源类型',
    dataIndex: 'sourceType',
    width: 150,
    hideInSearch: false,
    valueEnum: {
      invite: '邀请新用户',
      goods: '购买',
      orderSettle: '订单结算',
      orderRefund: '订单退款',
      direct: '直推奖励',
      indirect: '间推奖励',
      signIn: '签到',
      withdrawApply: '提现申请',
      withdrawReject: '提现驳回',
      system: '系统发放',
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 200,
  },
])
</script>
<template>
  <CModal v-model:visible="props.show" :footer="false" :mask-closable="false" width="1000px" title="余额记录" @cancel="emit('update:show', false)">
    <ProTable :columns="columns" :request="request" row-key="id" :form-ref="ref => (formRef = ref)" :pagination="pagination" header-title="" column-resizable :scroll="{ x: 1000 }" :params="searchQuery" :bordered="{ cell: true }" :action-ref="ref => (actionRef = ref)">
      <template #option-render="{ dom, reset }">
        <component :is="dom[1]" />
        <component :is="dom[0]" />
      </template>
    </ProTable>
  </CModal>
</template>
<style lang="less" scoped></style>
